<?php

namespace App\Http\Middleware;

use App\Constants\UserStatusConstant;
use App\Helpers\RestUtils;
use App\Models\Factory\AccreditFactory;
use App\Models\Factory\IdentityFactory;
use App\Models\Factory\UserFactory;
use App\Models\Factory\UserImageFactory;
use App\Models\Factory\UserStatusFactory;
use Closure;
use App\Helpers\RestResponseFactory;


/**
 * 验证图片状态中间件
 *
 * Class TokenMiddleware
 * @package App\Http\Middleware
 */
class AccreditStatusMiddleware
{
    public function handle($request, Closure $next)
    {
        $result =  $next($request);

        $uid = $request -> get('uid');
        if($uid) {
            //用户授权状态
            $taobaoStatus = AccreditFactory::Taobao($uid);
            //修改用户状态表里淘宝状态
            $resultTao = UserStatusFactory::updateUserStatus($uid, $taobaoStatus, UserStatusConstant::TAO);

            $aliStatus = AccreditFactory::Ali($uid);
            //修改用户状态表里淘宝状态
            $resultAli = UserStatusFactory::updateUserStatus($uid, $aliStatus, UserStatusConstant::ALI);

            $capStatus = AccreditFactory::Cap($uid);
            //修改用户状态表里淘宝状态
            $resultCap = UserStatusFactory::updateUserStatus($uid, $capStatus, UserStatusConstant::CAP);

            $step2 = ($taobaoStatus && $aliStatus && $capStatus) ? '1' : '0';

            //修改授权状态
            $resultAccredit = UserStatusFactory::updateUserStatus($uid, $step2, UserStatusConstant::ACCREDIT);
        }
            return $result;


    }

}
